package com.fili.core.params;

import com.fili.core.keygen.EncodedPermission;

import java.io.*;
import java.util.Date;
import java.util.Calendar;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Oct 14, 2006
 * Time: 10:10:50 PM
 */
public class DryParams implements Serializable
{
    private static final long serialVersionUID = 4060309176087675115L;
    private String fileName = "params.dat";

    public String registeredName = "";
    public String registeredKey = "";
    public transient EncodedPermission permission;
    public transient boolean demoMode;

    public String serialPort = "com1";
    public int serialBaud = 2400;
    public int serialDataBits = 8;
    public int serialParity = 0;
    public int serialStopBits = 1;

    public long firstRun = 0;
    public long lastRun=0;

    public static DryParams getDryParams(String fileName)
    {
        DryParams dp;
        try
        {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName));
            dp = (DryParams) ois.readObject();
            dp.fileName = fileName;
            ois.close();
            return dp;
        }
        catch (FileNotFoundException e)
        {
//            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }

        dp = new DryParams();
        dp.fileName = fileName;
        return dp;
    }

    public void saveParams()
    {
        try
        {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName));
            oos.writeObject(this);
            oos.flush();
            oos.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
